package sg.edu.nus.iss.billing.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Map;

import sg.edu.nus.iss.billing.localization.MessageKeyManager;

public class Util {

	public static boolean isEmpty(String s) {

		if (s==null)
			return true;
		if (s.trim().equals(""))
			return true;
		return false;
	}

	public static boolean isEmpty(Collection<?> c) {

		if (c==null)
			return true;
		return c.isEmpty();
	}

	public static boolean isEmpty(Map<?, ?> map) {

		if (map==null)
			return true;
		return map.isEmpty();
	}

	public static Date getDateFromString(String value) {

		if (isEmpty(value)) {
			return null;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(MessageKeyManager.getMessage("desc.dateFormat"));
		Date testDate = null;
		try {
			testDate = sdf.parse(value);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return testDate;
	}

	public static String getStringFromdate(Date date) {

		SimpleDateFormat sdf = new SimpleDateFormat(MessageKeyManager.getMessage("desc.dateFormat"));
		return sdf.format(date);
	}
	
	public static Date getCurrentDate(){
		return getDateFromString(getStringFromdate(new Date()));
	}
}
